package com.xinzhi.controller;

import com.xinzhi.service.PasswordService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/reset")
public class ResetPasswordController {

    @Autowired
    private PasswordService passwordService;

    /**
     * 重置密码
     * @param password
     * @param confirmPassword
     * @return
     */

    @PostMapping("/submit")
    public ResponseEntity<String> resetPassword(//@RequestParam String phone,
                                                @RequestParam String password,
                                                @RequestParam String confirmPassword){
                                                //@RequestParam(required = false) String code) {

        try {
            // 重置密码逻辑
            boolean resetSuccessful = passwordService.resetPassword(password, confirmPassword);

            if (resetSuccessful) {
                return ResponseEntity.ok("密码重置成功。");
            } else {
                return ResponseEntity.badRequest().body("密码重置失败。");
            }
        } catch (IllegalArgumentException e) {
            return ResponseEntity.badRequest().body(e.getMessage());
        }
    }
}
